package org.bilinc.gz001.entity.interfaces;

import org.apache.commons.lang.ObjectUtils;

public abstract class AbstractIdentityEntity implements AbstractEntity {
    public abstract Long getId();
    public abstract void setId(Long id);

    @Override
    public int hashCode() {
        Long id = getId();
        return id == null ? 0 : id.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;

        if (obj == null || !(obj instanceof AbstractIdentityEntity))
            return false;

        return ObjectUtils.equals(getId(), ((AbstractIdentityEntity) obj).getId());
    }
    @Override
    public String toString() {
        return String.format("%s#%d", getClass().getSimpleName(), getId());
    }


}
